﻿using Cheems.Control.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Cheems.Control.Controls
{
    public class HashAvatarImage : Image
    {
        /// <summary>
        /// 消息文本
        /// </summary>
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(HashAvatarImage), new PropertyMetadata(string.Empty, OnTextChanged));

        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HashAvatarImage thisControl = d as HashAvatarImage;
            if (string.IsNullOrEmpty(thisControl.Text))
            {
                thisControl.Source = null;
                return;
            }

            thisControl.Source = IdenticonGenerator.Generate(thisControl.Text);
        }
    }
}
